package com.lun.swordtowardoffer2.c03;

public class ValidPalidrome {

	public boolean validPalindrome(String s) {
		int start = 0, end = s.length() - 1;
		while(start < end) {
			if(s.charAt(start) != s.charAt(end))
				break;
			start++;
			end--;
		}
		
		return start == s.length() / 2 // 这里用到 || 的短路的性质
				|| isPalidrome(s, start + 1, end) //
				|| isPalidrome(s, start, end - 1);
	}
	
	private boolean isPalidrome(String s, int start, int end) {
		while(start < end) {
			
			if(s.charAt(start) != s.charAt(end))
				break;
			
			start++;
			end--;
		}
		return start >= end;
	}
	
}
